package com.common.help;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test {

	private static int clientReq = 5000;
	
	private static int threadNum = 200;
	
	private static int count = 0;
	
	public static void main(String[] args) throws Exception {

		//final Semaphore semaphore = new Semaphore(threadNum);
		final CountDownLatch countDownLatch = new CountDownLatch(clientReq);
		ExecutorService service = Executors.newCachedThreadPool();
		for(int i=0;i<clientReq;i++){
			service.execute(new Runnable() {
				@Override
				public void run() {
						add();
				}
			});
			countDownLatch.countDown();
		}
		countDownLatch.await();
		service.shutdown();
		System.out.println("------>"+count);
	}
	
	public static synchronized void add(){
		count++;
	}
}
